package com.example.mini_notepad.db;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class NoteDBHelper extends SQLiteOpenHelper {
	
	public NoteDBHelper(Context context){
		super(context, NoteContracts.DATABASE_NAME, null, NoteContracts.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		try{
			db.execSQL(NoteContracts.CREATE_TABLE_NOTE);
//			db.execSQL(NoteContracts.CREATE_TABLE_RECORD_NOTE);
		}catch(SQLException e){
			Log.w("NoteDBHelper", "SQLException occured when create tables.", e);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.w("NoteDBHelper", "Upgrading database from version " + oldVersion
				+ " to " + newVersion + ", which will destory all old data.");
		db.execSQL(NoteContracts.DROP_TABLE_NOTE);
//		db.execSQL(NoteContracts.DROP_TABLE_RECORD_NOTE);
		onCreate(db);
	}

}
